<?php $this->pageTitle='Quiz Details'; ?>
<div class="bodywrap"> 
<link href="<?php echo Yii::app()->request->baseUrl; ?>/css/analog.css" rel="stylesheet" media="screen"  />
<script type="text/javascript" src="<?php echo Yii::app()->request->baseUrl; ?>/js/jquery.js" ></script>
<script type="text/javascript" src="<?php echo Yii::app()->request->baseUrl; ?>/js/jquery.clock.js" ></script>
<script type="text/javascript">
 $(document).ready(function() {
   $('#analog-clock').clock({offset: '+5', type: 'analog'});
  
 });
</script>

<ul id="analog-clock" class="analog">
  <li class="hour"></li>
  <li class="min"></li>
  <li class="sec"></li>
  <li class="meridiem"></li>
</ul>

<?php 
if (isset($currentQuestionId) && $currentQuestionId && isset($attemptid) && $attemptid)
{
?>
<div style="float:left; margin:-40px 0 0 0; height:30px; font-size:14px; color:#CC3300; font-weight:bold;">
<?php echo "Your start Time : ".DATE("g:i a", STRTOTIME(Yii::app()->session['start_time']));  ?></div><div style="float:right; height:30px; margin:-40px 0 0 0; font-size:14px; color:#CC3300; font-weight:bold;">
<?php echo "Your End Time : ".DATE("g:i a", STRTOTIME(Yii::app()->session['end_time']));?>
</div>	
<?php
	$userAttemptDetails=UserQuizAttemptDetails::model()->getModel('ATTEMPT-QUIZ-ID', array('attemptid'=>(int)$attemptid,'questionid'=>(int)$currentQuestionId));
	if ($userAttemptDetails)
	{
		
		$question=Questions::model()->getModel('QUESTION-ID', array('questionid'=>$userAttemptDetails->question_id));
	   if ($question)
		{
			
		?>
		<form action ="<?php echo ApplicationConfig::getURL('', 'site', 'playQuiz',array('quizid'=>$question->quiz_id,'level'=>$level))?>" name="questiondetails" id="questiondetails" method="post" >
	<input type="hidden" name="question_id" id="question_id" value="<?php echo $question->id?>">
	<input type="hidden" name="quiz_id" id="quiz_id" value="<?php echo $question->quiz_id?>">
	<input type="hidden" name="attempt_id" id="attempt_id" value="<?php echo $attemptid?>">
	<?php //echo $question->title?>
	<div class="subhead"><?php echo $question->title;?></div>
    <div class="quiz">
    	<ul>
	<?php $options=Options::getList('QUESTION-ID',array('questionid'=>$question->id));
	foreach ($options as $option){
		
	?>
	<?php if ($option->id==$userAttemptDetails->option_id){?>
	<li onclick="setradio('<?php echo $option->id?>')"><input type="radio" id="<?php echo $option->id?>" name="answer" value="<?php echo $option->id?>" checked/> <?php echo $option->name?></li>
	<?php }else{?>
	<li onclick="setradio('<?php echo $option->id?>')"><input type="radio" id="<?php echo $option->id?>" name="answer" value="<?php echo $option->id?>" /> <?php echo $option->name?></li>
	<?php }?>
	<?php }?>
    	</ul>
    </div>
<div style="padding:8px 0 5px 0; margin:1px 0 0 0; background:#fff; border-top:0px solid #d6cbbc; border-bottom:0px solid #d6cbbc;	bottom:23px; width:100%">
    <div class="quizbutton">
		<?php if ($userAttemptDetails->order!="1"){?>
		<div class="back"><img src="<?php echo Yii::app()->request->baseUrl; ?>/images/back_but.png" border="0"  class="butimg" /><a href="<?php echo ApplicationConfig::getURL('', 'site', 'playQuiz',array('quizid'=>$quizdetails->quiz_id,'attemptid'=>$attemptid,'back'=>'back','questionid'=>$question->id,'order'=>$userAttemptDetails->order-1,'level'=>$level))?>"   class="back"> Back </a></div>
		 
    <?php }?>
    <div class="back"><a href="<?php echo ApplicationConfig::getURL('', 'site', 'afterQuizDetails',array('attemptid'=>$attemptid,'message'=>"",'quizid'=>$quizid,'level'=>$level))?>" >Quit</a></div>
		<?php $maxorder=UserQuizAttemptDetails::model()->getMaxOrderByAttemptId($attemptid);?>
		<div class="count"><?php echo $userAttemptDetails->order."/".$maxorder;?></div>
		<?php if ((int)$userAttemptDetails->order==(int)$maxorder){?>
		<div class="next"><img src="<?php echo Yii::app()->request->baseUrl; ?>/images/submit.png" border="0" style="right:0; margin: 12px 2% 0 0 !important; z-index: 999; position: absolute;" /><input type="submit" name="submit" value="submit" class="next"></div>
		<?php }else{?>
     	<div class="next"><img src="<?php echo Yii::app()->request->baseUrl; ?>/images/next_but.png" border="0"  style="right:0; margin: 15px 2% 0 0 !important; z-index: 999; position: absolute;"  /><input type="button" onclick="return checkoptions();" name="next" value="Next" class="next"></div>
		<div class="next"><input type="submit" id="skip" name="skip" value="skip" class="next" />
     
    </div>
        
		<?php }?><br clear="all" />	
</div>
</div>
	</form> 
		<?php 
		}
	}
}
else 
{
	echo "";
}
?>
<script type="text/javascript">
function checkoptions()
{

var options= document.forms[0].answer;
var cnt=false;

for(var i=0;i<options.length;i++)
{
	if(options[i].checked==true)
  {
		cnt=true;
     document.forms["questiondetails"].submit();    }
}
 
if(!cnt)
{
	 alert('please select option or skip the Question');
	 return false;
}


}

function setradio(id)
{
var options= document.forms[0].answer;
 
for(var i=0;i<options.length;i++)
{
	if(options[i].id==id)
	{
     options[i].checked=true;
  }
  else
  {
      options[i].checked=false;
  }
	
}

}
function timeout(){
    //var cas;
    $.ajax({
    type: "GET",
    url: "<?php echo yii::app()->createUrl('site/timeout',array('quizid'=>$quizid,'level'=>$level,'attemptid'=>$attemptid));?>",
    dataType: "json",
    success: function(jdata){
        if(jdata){
            alert(jdata);
            window.location="<?php echo ApplicationConfig::getURL('', 'site', 'afterQuizDetails',array('attemptid'=>$attemptid,'message'=>"",'quizid'=>$quizid,'level'=>$level))?>";
        }
        else
         setTimeout(function(){timeout();}, 1000);
    },
    error: function (xhr, ajaxOptions, thrownError){     
                   setTimeout(function(){timeout();}, 1000);
    }   
    });   
  }   
timeout();
</script>